home *** CD-ROM | disk | FTP | other *** search
/ ftp.whtech.com / ftp.whtech.com.tar / ftp.whtech.com / datasheets and manuals / Hardware / WHT / scsi / dsr_sources_2_2001 / allocate < prev    next >
Text File  |  2006-10-19  |  4KB  |  145 lines

  1. ************************************************************
  2. *                                                          *
  3. *  SCSI Sector Allocation Routine                          *
  4. *                                                          *
  5. *  This routine will search for free AUs in the bitmap.    *
  6. *                                                          *
  7. *  Inputs:                                                 *
  8. *     R3 - AU boundry                                      *
  9. *     R6 - SCSI ID in high byte                            *
  10. *     R7 - Preferred starting AU                           *
  11. *     R8 - # of AUs wanted                                 *
  12. *                                                          *
  13. *  Outputs:                                                *
  14. *     R4 - Actual number of AUs allocated.                 *
  15. *     R5 - Starting AU                                     *
  16. *                                                          *
  17. ************************************************************
  18.  
  19. ALLOC  DATA ALWS
  20.        DATA ALOC0
  21.  
  22. ALOC0  SOC  @EQBIT,R15       Set caller's equal bit
  23.  
  24.        MOV  @12(R13),R6      Get SCSI ID
  25.        MOV  @14(R13),R5      Get starting AU
  26.        JEQ  ALOC50           Branch if no starting AU given
  27.  
  28.        CLR  R7
  29.        AI   R5,256*8         VIB take up 1st 256 bytes of disk
  30.  
  31.        MOV  R5,R0
  32. *      ANDI R0,>000F         Mask out bit position
  33.        MOV  R5,R1            R1 will contain byte offset
  34.        ANDI R1,>0FF0         within the sector
  35.        SRL  R1,3
  36.        AI   R1,SECBUF
  37.        MOV  R5,R8
  38.        SRL  R8,12
  39.        LI   R4,>8000
  40.        SRC  R4,0
  41.        CLR  R7
  42.        BLWP @BANKIT          Read section of bitmap
  43.        DATA SCSIRD
  44.        JEQ  ALOC1
  45.        AI   R8,16            If read wasn't successful, try
  46.        BLWP @BANKIT          reading the copy of the bitmap
  47.        DATA SCSIRD
  48.        JNE  ALOCER           Couldn't read either copy - Error
  49.        AI   R8,-16
  50. ALOC1
  51.        MOV  *R1,R10
  52.        CZC  R4,R10           See if AU is free
  53.        JNE  ALOC50           If not, get 1st available AU
  54.        MOV  @14(R13),@10(R13)                  Set starting AU
  55. ALOC1A SOC  R4,*R1           Mark AU as allocated
  56.        LI   R2,1             R2 = # of AU's we allocate
  57.  
  58. ALOC2  C    R2,@16(R13)       See if we've allocated enough
  59.        JEQ  ALOC10
  60.        SRC  R4,1
  61.        JOC  ALOC3
  62. ALOC2A CZC  R4,R10
  63.        JNE  ALOC10
  64.        SOC  R4,*R1           Mark AU as allocated
  65.        INC  R2               Increment AU's allocated counter
  66.        JMP  ALOC2
  67.  
  68. ALOC3  INCT R1
  69.        CI   R1,SECBUF+>200   See if we've reached the end
  70.        JEQ  ALOC10
  71.        MOV  *R1,R10
  72.        JMP  ALOC2A
  73.  
  74. ALOC10 BLWP @BANKIT
  75.        DATA SCSIWT
  76.        AI   R8,16
  77.        BLWP @BANKIT
  78.        DATA SCSIWT
  79.        MOV  R2,@8(R13)       Save # of AU's in caller's R4
  80.        RTWP
  81.  
  82.  
  83. * Allocation error - clear the caller's EQ bit and return
  84. *
  85. ALOCER SZC  @EQBIT,R15
  86.        RTWP
  87.  
  88. * We have to search the bitmap for the 1st free AU
  89. *
  90. * For now, we will just look for the 1st available AU and return
  91. * it.  In a future better algorithm, we will look for contiguous
  92. * sectors and return as many as the user wants.
  93. *
  94.  
  95. ALOC50 MOV  @6(R13),R5       Get AU boundry
  96.        JGT  ALOC51
  97.        CLR  R5               Start at beginning of disk
  98.  
  99. ALOC51 AI   R5,256*8         Account for VIB at beginning of disk
  100.        MOV  R5,R0
  101. *      ANDI R0,>000F         Mask out bit position
  102.        MOV  R5,R1            R1 is offset withing sector buffer
  103.        ANDI R1,>0FF0
  104.        SRL  R1,3
  105.        AI   R1,SECBUF
  106.  
  107.        LI   R4,>8000
  108.        SRC  R4,0
  109.  
  110.        MOV  R5,R8            R8 is disk sector number
  111.        SRL  R8,12
  112.        CLR  R7
  113. ALOC54 BLWP @BANKIT          Read a sector of the bitmap
  114.        DATA SCSIRD
  115.  
  116.        JEQ  ALOC53
  117.        AI   R8,16            If we had an error reading the bitmap,
  118.        BLWP @BANKIT          then try reading the other copy
  119.        DATA SCSIRD
  120.  
  121.        JNE  ALOCER
  122.        AI   R8,-16
  123.  
  124. ALOC53 MOV  *R1,R10          See if AU is free
  125. ALO53A CZC  R4,R10
  126.        JEQ  ALOC55
  127.        INC  R5
  128.        SRC  R4,1             Not free, try next one
  129.        JNC  ALO53A
  130.        INCT R1
  131.        CI   R1,SECBUF+>200   See if we've reached the end of the buffer
  132.        JNE  ALOC53
  133.        INC  R8
  134.        LI   R1,SECBUF
  135.        CI   R8,16            See if disk is full
  136.        JL   ALOC54
  137.        CLR  @8(R13)
  138.        RTWP
  139.  
  140. ALOC55
  141.  
  142.        AI   R5,-256*8
  143.        MOV  R5,@10(R13)      Save AU in caller's R5
  144.        JMP  ALOC1A
  145.